package com.cangxuan.app.ui.user;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.alibaba.fastjson.JSONObject;
import com.cangxuan.app.R;
import com.cangxuan.app.entity.Article;

import com.cangxuan.app.ui.BaseActivity;
import com.cangxuan.app.utils.HttpUtils;
import java.util.List;
import java.util.Map;

/*公告内容
* 作者：田凯
* */

public class ArticleContentActivity extends BaseActivity {

    List<Article> articleList;
    Handler handler=new Handler();
    WebView webView;
    LinearLayout contentLoading;
    TextView txtNodata;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_article_content);
        setTitle("平台公告");
        contentLoading=findViewById(R.id.contentLoading);
        webView=findViewById(R.id.webView);
        txtNodata=findViewById(R.id.txtNodata);
        int id = getIntent().getIntExtra("id",0);
        txtNodata.setVisibility(View.GONE);
        contentLoading.setVisibility(View.VISIBLE);

        //调用API接口获取数据，
        Thread thread=new Thread(() -> {
            String get = HttpUtils.get("/api/article/content/get/"+id,null) ;
            JSONObject jsonResponse = JSONObject.parseObject(get);
            Map  object =(Map)jsonResponse.get("value");



//             Log.i( "content",object+"");
            //从json中直接获取article对象
            handler.post(()->{
                String html="<h3 align="+"'center'"+">"+object.get("title").toString()+"</h3>"
                        + "<h4 align="+"'center'"+">"+object.get("publishTime").toString()+"</h4>"
                        +object.get("content").toString();
                //加载网页内容
                webView.loadData(html, "text/html", "utf-8");

                contentLoading.setVisibility(View.GONE);
                //如果获取的是0条数据，则显示 txtNoData
                txtNodata.setVisibility(id== 0 ? View.VISIBLE : View.GONE);
            });
        });
        thread.start();

    }
}
